﻿using System;
using CustomerContactSystem.Core.Model;

namespace CustomerContactSystem.WebForms.Admin.Departments {
    public partial class Create : BasePage {

        protected void Page_Load(object sender, EventArgs e) {
        }

        protected void CreateNewDepartmentClick(object sender, EventArgs e) {
            var newDepartment = new Department
                {
                    DepartmentName = DepartmentName.Text
                };

            if (!IsValidObject(newDepartment, CreateNewDepartmentResultMessage)) {
                return;
            }

            DepartmentRepository.Add(newDepartment);
            //create default category
            var defaultCategory = new EnquiryCategory
                {
                    AvailableForSelection = true,
                    CategoryName = "General",
                    Department = newDepartment
                };
            EnquiryCategoryRepository.Add(defaultCategory);
            Response.Redirect("~/Admin/Departments/List.aspx");
        }
    }
}